package it.hive.model.domain.net;

import it.hive.io.settings.beans.Impostazione;

import java.util.HashMap;
import java.util.Properties;

public class InternetProxy implements Impostazione {
	public static final String PREFIX = "proxy.";
	public static final String PROXY_IP = "proxyIP";
	public static final String PROXY_PORT = "proxyPort";
	public static final String PROXY_USER = "proxyUser";
	public static final String PROXY_PASSWORD = "proxyPassword";

	private String proxyIP;
	private String proxyPort;
	private String proxyUser;
	private String proxyPassword;

	public String getProxyIP() {
		return proxyIP;
	}

	public void setProxyIP(String proxyIP) {
		this.proxyIP = proxyIP;
	}

	public String getProxyPort() {
		return proxyPort;
	}

	public void setProxyPort(String proxyPort) {
		this.proxyPort = proxyPort;
	}

	public String getProxyUser() {
		return proxyUser;
	}

	public void setProxyUser(String proxyUser) {
		this.proxyUser = proxyUser;
	}

	public String getProxyPassword() {
		return proxyPassword;
	}

	public void setProxyPassword(String proxyPassword) {
		this.proxyPassword = proxyPassword;
	}

	@Override
	public HashMap<? extends Object, ? extends Object> getSettingsMap() {
		HashMap<String, String> settingsMap = new HashMap<>();
		if (proxyIP != null) {
			settingsMap.put(PREFIX.concat(PROXY_IP), proxyIP);
		}
		if (proxyPort != null) {
			settingsMap.put(PREFIX.concat(PROXY_PORT), proxyPort);
		}
		settingsMap.put(PREFIX.concat(PROXY_USER), proxyUser != null ? proxyUser : "");
		settingsMap.put(PREFIX.concat(PROXY_PASSWORD), proxyPassword != null ? proxyPassword : "");
		return settingsMap;
	}

	@Override
	public void init(Properties propertiesFile) {
		if (propertiesFile.containsKey(PREFIX.concat(PROXY_IP))) {
			proxyIP = propertiesFile.getProperty(PREFIX.concat(PROXY_IP));
		}
		if (propertiesFile.containsKey(PREFIX.concat(PROXY_PORT))) {
			proxyPort = propertiesFile.getProperty(PREFIX.concat(PROXY_PORT));
		}
		if (propertiesFile.containsKey(PREFIX.concat(PROXY_USER))) {
			proxyUser = propertiesFile.getProperty(PREFIX.concat(PROXY_USER));
		}
		if (propertiesFile.containsKey(PREFIX.concat(PROXY_PASSWORD))) {
			proxyPassword = propertiesFile.getProperty(PREFIX.concat(PROXY_PASSWORD));
		}

	}

}
